<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page errorPage="errorShow.jsp" %>

<html>
<head>
<title>简易计算器</title>
</head>
<body>

<form name="form1" action="computer.jsp" method="post">
	请输入第一个数：<input type="text" name="num1"/><br><br>
	请选择运算方式：
	<select name="op">
		<option value="+">+</option>
		<option value="-">-</option>
		<option value="*">*</option>
		<option value="/">/</option>
	</select>	<br><br>
	请输入第二个数：<input type="text" name="num2"/><br><br>
	<input type="submit" name="submit" value="计算"/><input type="reset" value="重置"/>
	<input value="" name="computer">
	<br><br>	
</form>
<%
//只能接受整数，不是整数则跳到 errorShow,jsp页面
	if (request.getParameter("computer")!=null){
		String op = request.getParameter("op");

		Integer num1 = Integer.valueOf(request.getParameter("num1"));
		Integer num2 = Integer.valueOf(request.getParameter("num2"));
		int result=0;
		switch(op){
			case "*": result=num1*num2;
				break;
			case "/":result=num1/num2;
				break;
			case "+": result=num1+num2;
				break;
			case "-": result=num1+num2;
		}
		out.println(num1+op+num2+"="+result);
	}
%>
</body>
</html>